using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Data;
using TexasHoldEmCroupier.Views;
using TexasHoldEmCroupier.Enumerators;
using TexasHoldEmCroupier.UserControls;

namespace TexasHoldEmCroupier.ApplicationController
{
    public partial class Controller
    {
        #region Methods
        private void NumberOfPlayersWizardView_Show(
            int theNumberOfPlayers)
        {
            NumberOfPlayersWizardView theView =
                new NumberOfPlayersWizardView();

            theView.buttonNext.Click +=
                new EventHandler(NumberOfPlayersWizardView_buttonNext_Click);
            theView.buttonExit.Click +=
                new EventHandler(NumberOfPlayersWizardView_buttonExit_Click);

            theView.NumberOfPlayers = theNumberOfPlayers;

            theView.ShowDialog(this._MainView);
        }

        #region Event Handlers
        private void NumberOfPlayersWizardView_buttonExit_Click(
            object sender, 
            EventArgs e)
        {
            Button theCancelButton =
                sender as Button;
            NumberOfPlayersWizardView theParentView =
                theCancelButton.FindForm() as NumberOfPlayersWizardView;

            switch (MessageBox.Show(
                   this._MainView,
                   "Are you sure you want to exit the game?",
                   this._MainView.Text,
                   MessageBoxButtons.YesNo,
                   MessageBoxIcon.Question,
                   MessageBoxDefaultButton.Button2))
            {
                case DialogResult.Yes:
                    this._MainView.DialogResult = DialogResult.Abort;
                    this._MainView.Close();
                    return;
            } 
        }

        private void NumberOfPlayersWizardView_buttonNext_Click(
            object sender, 
            EventArgs e)
        {
            Button theNextButton =
                sender as Button;
            NumberOfPlayersWizardView theParentView =
                theNextButton.FindForm() as NumberOfPlayersWizardView;

            theParentView.Hide();

            this._MainView.SmallBlind = 
                theParentView.SmallBlindValue;
            this._MainView.BigBlind =
                theParentView.SmallBlindValue * 2;

            for (int i = 0; i < theParentView.NumberOfPlayers; i++)
            {
                PlayerStrip thisPlayer = new PlayerStrip();
                
                thisPlayer.OnAllIn += new EventHandler(PlayerStrip_OnAllIn);
                thisPlayer.OnBet += new EventHandler(PlayerStrip_OnBet);
                thisPlayer.OnCall += new EventHandler(PlayerStrip_OnCall);
                thisPlayer.OnCheck += new EventHandler(PlayerStrip_OnCheck);
                thisPlayer.OnFold += new EventHandler(PlayerStrip_OnFold);
                thisPlayer.OnRaise += new EventHandler(PlayerStrip_OnRaise);

                thisPlayer.Disable();
                thisPlayer.Visible = false;
                
                this._MainView.panelPlayers.Controls.Add(
                    thisPlayer);
            }

            this.PlayerDetailsWizardView_Show(0);
        }
        #endregion
        #endregion
    }
}
